﻿using System;
using System.Collections.Generic;

namespace CPlatePrintSys.Server.Models
{
    // AccountController 操作返回的模型。

    public class ExternalLoginViewModel
    {
        public string Name { get; set; }

        public string Url { get; set; }

        public string State { get; set; }
    }

    public class ManageInfoViewModel
    {
        public string LocalLoginProvider { get; set; }

        public string Email { get; set; }

        public IEnumerable<UserLoginInfoViewModel> Logins { get; set; }

        public IEnumerable<ExternalLoginViewModel> ExternalLoginProviders { get; set; }
    }

    public class UserInfoViewModel
    {
        public string id { get; set; }
        public string Username { get; set; }

        public string Fullname { get; set; }

        public bool HasRegistered { get; set; }

        public string LoginProvider { get; set; }

        public IList<string> Roles { get; set; }
    }

    public class UserLoginInfoViewModel
    {
        public string LoginProvider { get; set; }

        public string ProviderKey { get; set; }
    }

    /// <summary>
    /// 用于API GET请求的分页输入参数模型
    /// </summary>
    public class PagingParameters
    {
        private const int MaxPageSize = 50; // 限制最大页面大小
        private int _pageSize = 10;

        public int PageNumber { get; set; } = 1;

        public int PageSize
        {
            get => _pageSize;
            set => _pageSize = (value > MaxPageSize) ? MaxPageSize : (value <= 0 ? 10 : value);
        }
    }

    /// <summary>
    /// 用于API返回的分页结果通用视图模型
    /// </summary>
    public class PagedResultViewModel<T> where T : class
    {
        public int CurrentPage { get; set; }
        public int PageSize { get; set; }
        public int TotalCount { get; set; }
        public int TotalPages { get; set; }
        public List<T> Data { get; set; }

        public PagedResultViewModel(List<T> data, int pageNumber, int pageSize, int totalCount)
        {
            Data = data;
            CurrentPage = pageNumber;
            PageSize = pageSize;
            TotalCount = totalCount;
            TotalPages = (int)Math.Ceiling(totalCount / (double)pageSize);
        }
    }

    /// <summary>
    /// DTO 用于 'GET api/Account/GetRoles'
    /// </summary>
    public class RoleViewModel
    {
        public string Id { get; set; }
        public string Name { get; set; }
    }
}
